package topo.sourcecode;

import java.awt.Font;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import javax.swing.JList;

public class SourceCodeList extends JList {
    public static Map<String, String> sourceNameMap = null;

    public static Vector<String> sourceNameVector = null;

    public static String SOURCECODE_PATH = "codefile/";

    public static final String[][] sourceNameArray = { { "按IP范围搜索设备", "AutoDiscoverByIpAction" }, { "按网络号搜索设备", "AutoDiscoverByNetAction" }, { "按路由器跳转搜索设备", "AutoDiscoverByRouterAction" }, { "漫游搜索设备", "AutoDiscoverByIPRoamingAction" }, { "搜索设备资源", "ResourcesSearchAction" }, { "查看设备系统信息", "SNMPGetMibSystem" }, { "网络接口管理信息", "MonitorIfTableAction" }, { "查看网络流量状态", "SNMPGetIfNetStatus" }, { "查看IP数据包状态", "SNMPGetIP" }, { "查看IP地址信息", "SNMPGetIPAddr" }, { "查看路由信息", "SNMPGetRouterInfo" }, { "查看设备主MAC信息", "SNMPGetMAC" }, { "查看主MAC和端口信息", "SNMPGetMACAndPort" }, { "查看MAC-IP信息", "SNMPGetMACIPAction" }, { "查看交换机端口转发信息", "SNMPGetSwitchSFP" }, { "搜索直连下挂设备", "SNMPDiscoverSwitchPC" }, { "查看TCP连接状态", "SNMPGetTCPConn" }, { "查看UDP侦听状态", "SNMPGetMibUdpEntry" }, { "查看SNMP代理状态", "SNMPGetSnmp" }, { "查看磁盘和内存存储状态", "SNMPGetDiskMemo" }, { "查看设备设施状态", "SNMPGetMibDevice" }, { "查看CPU状态", "SNMPGetCpu" }, { "查看软件安装状态", "SNMPGetInstallSw" }, { "查看进程状态", "SNMPGetRunSW" }, { "查看进程CPU和内存", "RunSWCpuAndMemAction" } };

    static {
        sourceNameMap = new HashMap();
        sourceNameVector = new Vector();
        for (int i = 0; i < sourceNameArray.length; i++) {
            sourceNameMap.put(sourceNameArray[i][0], sourceNameArray[i][1]);
            sourceNameVector.add(sourceNameArray[i][0]);
        }
    }

    public SourceCodeList() {
        setListData(sourceNameVector);
        setSelectionMode(0);
        setFont(new Font("Courier", 0, 12));
    }

    public static String readSourceCodeFromFile(String sourceName) throws Exception {
        String fileName = (String) sourceNameMap.get(sourceName) + ".txt";

        StringBuffer contentBuffer = new StringBuffer();
        InputStream inStream = SourceCodeList.class.getResourceAsStream(SOURCECODE_PATH + fileName);
        BufferedReader bfReader = new BufferedReader(new InputStreamReader(inStream));
        String line;
        while ((line = bfReader.readLine()) != null) {
            contentBuffer.append(line + "\n");
        }
        String content = contentBuffer.toString();
        return content;
    }
}